import * as path from 'node:path'
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig((env) => {
  const viteEnv = loadEnv(env.mode, process.cwd())

  return {
    resolve: {
      // 设置别名
      alias: {
        '@': path.resolve(__dirname, './src'),
      },
    },
    plugins: [vue()],
    server: {
      port: 8080, // 启动端口
      host: '0.0.0.0',
      // 设置 https 代理
      proxy: {
        '/api': {
          target: viteEnv.VITE_APP_API_BASE_URL,
          changeOrigin: true, // 允许跨域
          // rewrite: path => path.replace('/api/', '/api/'),
        },
        '/getFile': {
          target: viteEnv.VITE_APP_API_BASE_URL,
          changeOrigin: true, // 允许跨域
        },
      },
    },
  }
})
